const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            cityValue: [],
            cityValue1:[],
            city:[],
            city1:[],
            blue_plate:[]
        };
    },
    mounted() {
        this.getCategory();
        this.getCity();
    },
    watch:{
        'dataForm.Article_Exchange_SerialNumber'(val){
            let str = this.dataForm.VillageNumber
            if (str.substring(0,6)) {
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/clientOperation/getDistrictTree`,
                    type: "GET",
                    data: {
                        DistrictCode:str.substring(0,6)
                    },
                    success: (data) => {
                       this.city1 = data[0].children;
                       this.cityValue1 = [str.substring(0,9),str];
                       this.cityValue = [str.substring(0,2)+'0000',str.substring(0,4)+'00',str.substring(0,6)]
                       this.changeCity1( this.cityValue1)
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }
        },
    },
    methods: {
        getCity(){
            $.ajax({
                url: `${absolutepath()}api/Districtjl.json`,
                method: "get",
                success: (data) => {
                    data.forEach(item=>{
                        item.children.forEach(ite=>{
                            ite.children.forEach(it=>{
                                it.children = undefined
                            })
                        })
                    })
                    this.city = data;
                    if (this.action == 'Add') {
                        this.cityValue = ["230000", "232700", "232723"]
                        this.changeCity(this.cityValue);
                    }
                },
                
            });
        },
        changeCity1(val){
            if (val.length > 0) {
                this.dataForm.TownNumber = val[0];
                this.dataForm.VillageNumber = val[1];
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryBySQLSerialNumber`,
                    method: "post",
                    data: {
                        SQLSerialNumber: 'f_blue_plate_information',
                        Condition: '',
                        ExtensionCondition: window.btoa(unescape(encodeURIComponent("AND blue_plate_information.Village_SerialNumber = '" + val[0] + "'"))),
                    },
                    success: (data) => {
                        this.blue_plate = data;
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest)
                    },
                })
            } else {
                this.dataForm.VillageNumber = '';
            }
        },
        changeCity(val){
            this.dataForm.ProvinceNumber = val[0];
            this.dataForm.CityNumber = val[1];
            this.dataForm.CountyNubmer = val[2];
            if (val.length > 0) {
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/clientOperation/getDistrictTree`,
                    type: "GET",
                    data: {
                        DistrictCode: val[2]
                    },
                    success: (data) => {
                       this.city1 = data[0].children;
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }
        },
        getCategory() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'news_category',
                    Condition: "Row_Status='0'",
                },
                success: (data) => {
                    this.category = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        }
    },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus,{locale: zhCn});
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-select', ylSelect);
app.component('yl-text-editor', ylTextEditor);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
